import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/pages/common/LoadBuilder.dart';
import 'package:xiongan_app_yy/provider/autopicking_provider.dart';
import 'package:xiongan_app_yy/utils/toast_utils.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class AutoPickingType extends StatefulWidget{
String id;
  @override
  State<StatefulWidget> createState() {
    return AutoPickingTypeState();
  }

AutoPickingType(this.id);

}

class AutoPickingTypeState extends State<AutoPickingType>{
  List backgroundList = [ "assets/images/auto_mounting_bg1.png", "assets/images/auto_mounting_bg2.png"];
  List nameList = [ "下架出库", "下架后托盘上架"];
  List beanList = [ "emptyList", "needPutList"];
  @override
  void initState(){
    super.initState();
//    WidgetsBinding.instance.addPostFrameCallback((_){
//
//    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "下架类型选择",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body:  LoadBuilder(
          visibility: Provider.of<AutoPickingProvider>(context).netStatus2,
          builder:GridView(
              padding: EdgeInsets.only(left: 12,right: 12,top: 12),
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                crossAxisCount: 2, //横轴三个子widget
                childAspectRatio: 3/5, //宽高比为1时，子widget
                crossAxisSpacing: 12.0,
                mainAxisSpacing: 12.0,
              ),
              children: getGridViews()
          )),

    );
  }


  List<Widget> getGridViews(){
    Map details=Provider.of<AutoPickingProvider>(context).detailListData;
    List<Widget> gridViews=new List();
    if(details.length>0){
      gridViews.add(
        GestureDetector(
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(backgroundList[0]),
                    fit: BoxFit.fill)
            ),
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("${nameList[0]}"),
                Text("${details["emptyList"].length??"0"}",style: TextStyle(color: Colors.black,fontSize: 38),)
              ],
            ),
          ),
          onTap: (){
            if(details["emptyList"].length>0){
              Provider.of<AutoPickingProvider>(context).setTypeDetailData(datas: details["emptyList"]);
              Navigator.pushNamed(context, "/autopicking_detail_list",arguments: widget.id);
            }else{
              TostUtil.showToast("没有可执行任务");
            }
          },
        ),
      );
      gridViews.add(
        GestureDetector(
          child: Container(
            decoration: BoxDecoration(
                image: DecorationImage(
                    image: AssetImage(backgroundList[1]),
                    fit: BoxFit.fill)
            ),
            alignment: Alignment.center,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Text("${nameList[1]}"),
                Text("${details["needPutList"].length??"0"}",style: TextStyle(color: Colors.black,fontSize: 38),)
              ],
            ),
          ),
          onTap: (){
            if(details["needPutList"].length>0){
              Provider.of<AutoPickingProvider>(context).setTypeDetailData(datas: details["needPutList"]);
              Navigator.pushNamed(context, "/autopicking_detail_list",arguments: widget.id);
            }else{
              TostUtil.showToast("没有可执行任务");
            }
          },
        ),
      );
    }

    return gridViews;
  }
}